package tabelas.controle.Uf;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="ufbean")
@RequestScoped
public class UfBean {
	private UF uf = new UF();
	private List<UF> uflist;
	private Map<String, Integer> uflists = new HashMap<String, Integer>();
	public String suf;
	UfDAOImp ufdaoimp = new UfDAOImp();
	
	public UfBean(){
		//uflists = new HashMap<String, String>();
		ListarUF();
	}	
	public String novo(){
		this.uf = new UF();
		return "UF";
	}
	public String inseriruf(){
		UfRN ufrn = new UfRN();
		ufrn.inseriruf(this.uf);
		return "Inserir UF";
	}
	public String alteraruf(){
		UfRN ufrn = new UfRN();
		ufrn.alteraruf(this.uf);
		return "Alterar UF";
	}
	public String excluiruf(){
		UfRN ufrn = new UfRN();
		ufrn.excluiruf(this.uf);
		return "Excluir UF";
	}
	public List<UF> getListUF(){
		UfRN ufrn = new UfRN();
		uflist = ufrn.listarUF();
		return uflist;
	}
	public List<String> ListarUF(){
       uflist = new ArrayList<UF>();
       List<String> results = new ArrayList<String>();
       Integer tam, i = 0;
       try {
    	   uflist = ufdaoimp.listarTUF();
           tam = uflist.size();
           while (i < tam  ){
        	   uflists.put(uflist.get(i).getNmuf(), uflist.get(i).getIduf());
        	   i++;
           }
       } catch (Exception e) {
    	   e.printStackTrace();
       }
       return results;
    }
	
	public UF LocalizarUFSelect(UF uf){
		UF ufselect = new UF();
		//ufdaoimp.localizaUFSelect(sidUF)		
		return ufselect;
	}
	
	public List<String> completeUF(String query) {
        List<String> results = new ArrayList<String>();
        List<String> val = new ArrayList<String>();
        try {
                val = ufdaoimp.ListaUFC(query);
                results = val;
        } catch (Exception e) {
                e.printStackTrace();
        }
        return results;        
	}	
	public UF getUf() {
		return uf;
	}
	public void setUf(UF uf) {
		this.uf = uf;
	}
	public List<UF> getUflist() {
		return uflist;
	}
	public void setUflist(List<UF> uflist) {
		this.uflist = uflist;
	}
	public String getSuf() {
		return suf;
	}
	public void setSuf(String suf) {
		this.suf = suf;
	}
	public Map<String, Integer> getUflists() {
		return uflists;
	}
	public void setUflists(Map<String, Integer> uflists) {
		this.uflists = uflists;
	}
	
}
